package com.dsj.gxrd.modules.controller.activity;

import com.dsj.gxrd.modules.activity.domain.dto.RdGroupDto;
import com.dsj.gxrd.modules.activity.domain.vo.GroupUserVo;
import com.dsj.gxrd.modules.activity.domain.vo.RdGroupVo;
import com.dsj.gxrd.modules.activity.service.RdGroupService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author songpin566
 * @date 2023/09/14
 **/
@Api(tags = "分组分类")
@RestController
@RequestMapping("/group")
public class RdGroupController extends BaseController {

    @Autowired
    private RdGroupService rdGroupService;

    @RequiresPermissions("group:category:list")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(value = "name", required = false) String name,
                              @RequestParam(value = "groupName", required = false) String groupName) {
        startPage();
        List<RdGroupVo> list = rdGroupService.selectRdGroupList(name, groupName);
        return getDataTable(list);
    }

    @RequiresPermissions("group:category:add")
    @PostMapping()
    public AjaxResult add(@RequestBody RdGroupDto rdGroupDto) {
        return toAjax(rdGroupService.insertRdGroup(rdGroupDto));
    }

    @RequiresPermissions("group:category:edit")
    @PutMapping()
    public AjaxResult edit(@RequestBody RdGroupDto rdGroupDto) {
        return toAjax(rdGroupService.updateRdGroup(rdGroupDto));
    }

    @RequiresPermissions("group:category:query")
    @GetMapping("/{groupId}")
    public TableDataInfo getInfo(@PathVariable Long groupId,@RequestParam(value = "name",required = false)String name) {
        startPage();
        List<GroupUserVo> groupUserVoList = rdGroupService.getInfo(groupId,name);
        return getDataTable(groupUserVoList);
    }

    @RequiresPermissions("group:category:user:del")
    @DeleteMapping("/user/{groupUserIds}")
    public AjaxResult removeGroupUser(@PathVariable List<Long> groupUserIds) {
        return rdGroupService.removeGroupUser(groupUserIds);
    }

    @RequiresPermissions("group:category:del")
    @DeleteMapping("/{groupIds}")
    public AjaxResult removes(@PathVariable List<Long> groupIds) {
        return rdGroupService.removes(groupIds);
    }


}
